//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.Web.UI.WebControls;
using CommunityServer.Blogs.Components;
using CommunityServer.Components;
using CommunityServer.Controls;

namespace CommunityServer.Blogs.Controls
{
	/// <summary>
	/// Summary description for AboutAuthor.
	/// </summary>
    public class AboutAuthor : WeblogThemedControl
    {
        public AboutAuthor()
        {
		
        }

        private  IText bio;
        private IText name;

        private string _userName = null;
        public string UserName
        {
            get{return _userName;}
            set{_userName = value;}
        }

        public override void DataBind()
        {
            base.DataBind ();

            if(!Globals.IsNullorEmpty(UserName))
            {
                User u = Users.GetUser(0,UserName,false,true);
                if(u != null)
                {
                    if(name != null)
                    {
                
                        name.Text = u.DisplayName;
                    }
                    
                    if(bio != null && !Globals.IsNullorEmpty(u.Profile.Bio))
                    {
                        bio.Text = u.Profile.Bio;
                    }
                }

               
            }

        }

        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender (e);
            if(bio == null || Globals.IsNullorEmpty(bio.Text))
            {
                this.Controls.Clear();
                this.Visible = false;
            }
        }



        /// <summary>
        /// Override this method to attach templated or external skin controls to local references.
        /// </summary>
        /// <remarks>
        /// This will only be called if the non-default skin is used.
        /// </remarks>
        protected override void AttachChildControls()
        {
            bio = FindText("bio");
            name = FindText("username");


        }
    }
}
